package com.cheney.demo.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.cheney.demo.fallback.MyFallbackClass;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @author si.chen
 * @date 2021/6/30 16:07
 */
@RestController
@RequestMapping("/sentinel")
public class SentinelController {

    @SentinelResource(value = "cs", fallback = "fallbackCs", fallbackClass = MyFallbackClass.class)
    @GetMapping("/cs")
    public String cs() {
        return "ok";
    }

    @GetMapping("/cs2")
    public String cs2() throws Exception {
        TimeUnit.MILLISECONDS.sleep(1500);
        return "ok";
    }
}
